<template>
    <div class="seach-suggestions"> 
        <van-cell :title="str" icon="search"  v-for="(str,index) in searchSuggestions" :key="index" @click="$emit('search',str)"/>
    </div>
</template>
<script>
 import { getSearchSuggestions } from '@/api/search'
//  引入函数防抖
 import {debounce} from 'lodash' 

export default {
 name: 'SearchSuggestions',
 data() {
     return {
        searchSuggestions: []
     }
 },
 methods: {
 },
 props: {
     //搜索框里输入的文字
     searchtext: {
         type: String,
         required: true
     }
 },
 watch: {
     searchtext: {
         handler: debounce(async function(){
             const { data } = await getSearchSuggestions(this.searchtext)
             this.searchSuggestions = data.data.options
             console.log('我是搜索预测请求回来的数据');
             console.log(data);
             //找到接口数据
            //  /请求获取数据
            //模板绑定展示
             console.log('hello');
         }, 200),
        immediate: true,
     }
 }
}
</script>
<style lang="less" scoped>

</style>